#version 460
#define GLSLIFY 1

layout(std140, set=0, binding=0) uniform U_Matrix {
	mat4 mat_ProjecView;	
};

//layout(std140, set=1, binding=1) uniform mat4 Model_Matrix;
layout(std140, binding = 1) readonly buffer U1_Matrix {
	mat4 mat_Model[];
};

layout(std140, column_major, binding = 2) uniform U2_Matrix {
	uvec4 mat_Dim;
	//整个域世界大小
	vec4 WorldSize;
	//域单元间隔
	vec4 UnitInterval;
};

layout(location = 0) in vec4	inDir_Speed;
layout(location = 1) in float	inDensity;

layout(location = 0) out vec4 vColor;
out gl_PerVertex {
	vec4 gl_Position;
	float gl_PointSize;
};

void main(void){
	vec4 vert;
	uint Z = (gl_VertexIndex / (mat_Dim.y*mat_Dim.x));
	uint index = gl_VertexIndex - (Z * mat_Dim.y*mat_Dim.x);
	uint Y = index / mat_Dim.x;

	vert.x = UnitInterval.x * (index - (mat_Dim.x * Y));
	vert.y = UnitInterval.y * Y;
	vert.z = UnitInterval.x * Z;
	vert.w = 1.0;

	vert.xyz -= WorldSize.xyz*0.5;
	vert.xyz += UnitInterval.xyz*0.5;

	//gl_Position = mat_ProjecView * mat_Model[gl_InstanceIndex] * vert;
	gl_Position = mat_ProjecView * vert;

	if(inDensity >= 0.5){
		gl_PointSize = 4.1;
		vColor = vec4(1, 1, 0, 1.0);

	}
	else {
		gl_PointSize = 0.1;
		vColor = vec4(0, 0, 1, 0.5);
	}

	gl_PointSize = min(4.0, 3);
	
	//gl_PointSize = 3.0;
	
}

